#include "CarControl.h"
#include "Delay.h"
#include "gec_uart.h"
#include "gec_int.h"
#include "gec_gpio.h"
#include "LED.h"

unsigned char recvbuf='0';
extern int mode;

void uart_isr() {
  Gec_UART_Read(USART2,&recvbuf,1);


  switch(recvbuf) {
  case '0':
    mode = 0;
    break;
  case '9':
    mode = 1;//开启避障
    break;
  case 's':
    mode = 2;//开启寻路
    break;
  case 't':
    mode = 3;//开启蓝牙控制
    break;
	case 'a':
		setLEDValue(3,0);
	break;
	case 'b':
		setLEDValue(3,1);
	break;
	default:;
  }
}

void Bluetooth_uart_init(void) {
  //初始化uart
  Gec_UART_Init(USART2,9600,USART_Parity_No,8,USART_StopBits_1);
  Gec_Int_Register(BSP_INT_ID_USART2,uart_isr);//注册中断回调函数
  Gec_Int_Enable(BSP_INT_ID_USART2);
}




void startBluetoothControl() {

  switch(recvbuf) {
  case '1':
    carGoForward();
    break;
  case '2':
    carGoBack();
    break;
  case '3':
    carTurnLeft();
    break;
  case '4':
    carTurnRight();
    break;
  case '5':
    leftWheelRun();
    break;
  case '6':
    leftWheelBack();
    break;
  case '7':
    rightWheelRun();
    break;
  case '8':
    rightWheelBack();
    break;
  case 'v':
    carStop();
    break;
  default:
    ;
  }
}
